
// 回合结算模块
class winningCard extends eui.Component{
    private titleUi:eui.Image;
    private bg:eui.Image;
    private handPokerBg:egret.Sprite;
    public ON_CLOSE:string = "onClose";
    private lsNum:number = 0;
    private objList:Array<any> = new Array();

    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/end/winningCardSkin.exml";
    }
    private onComplete(){
        this.handPokerBg = new egret.Sprite();
        this.handPokerBg.y = 60;
        this.addChild(this.handPokerBg);
    }
    private lucks = []
    private clearLucky() {
        console.log('clearLucky');
        this.lucks.forEach(luckyYao => {
            if (luckyYao.parent) {
                this.handPokerBg.removeChild(luckyYao)
            }
        })
    }
    public setContent(msg:any){ 
        let msgList:any = msg;
        let bgWidth:number;
        let pokerMc:handPoker;
        
        this.objList = [];
        this.lsNum = 0;
        this.clearLucky()
        console.log('wincard', msg);
        for(var i=0;i<msgList.length;i++){
            if (!msg[i].card.suitType) {
                msgList[i].points.forEach((point, index2) => {
                    const luckyYao = new Yaoshaizidange()
                    luckyYao.x = 90*i + index2 * 32;//15+(32*((i+1)%5));
                    luckyYao.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
                    this.handPokerBg.addChild(luckyYao)
                    console.log('luckyYao .... ', luckyYao);
                    luckyYao.playAction(point)
                    this.lucks.push(luckyYao)
                })
                // const luckyMc = new lucky()
                // luckyMc.setContent(msgList[i].points, msgList[i].points.length)
                // this.addChild(luckyMc)
                // luckyMc.x = 32*i + i * 64
                // luckyMc.y = 30;
                // this.lucks.push(luckyMc)
                continue 
            }
            pokerMc = new handPoker();
            pokerMc.setContent(msgList[i].card.suitType+"_"+msgList[i].card.count+"_png");
            this.handPokerBg.addChild(pokerMc);            
            pokerMc.x = pokerMc.width*i;                        
            pokerMc.y = 10;        

            pokerMc.showBack();
            this.objList.push({obj:pokerMc,win:msgList[i].win});

            bgWidth = pokerMc.width*i;
        }
        
        if(bgWidth>500){
            this.bg.width = bgWidth+100;
        }else{
            this.bg.width = 550;
        }
        this.handPokerBg.x = (this.bg.width - (pokerMc.width*i))/2;
        this.titleUi.x =  (this.bg.width - this.titleUi.width)/2;
        this.width = this.bg.width;
        this.showAction();
    }

    private showAction(){
             if(this.lsNum<this.objList.length){
                 if(this.objList[this.lsNum].win == true){                     
                     egret.Tween.get(this.objList[this.lsNum].obj).to({y:0},100,egret.Ease.backInOut).call(()=>{                         
                        // StageData.soundObj.soundSinglePlay("tuopan");
                        egret.Tween.removeTweens(this.objList[this.lsNum].obj);
                        this.objList[this.lsNum].obj.showBack(false); 
                        /*let movie:egret.MovieClip = MyLibrary.createMovieClipByName("winAction",true);
                        movie.x = this.objList[this.lsNum].obj.x+(this.objList[this.lsNum].obj.width/2);
                        movie.y = this.objList[this.lsNum].obj.y+(this.objList[this.lsNum].obj.height/2);
                        movie.play();
                        this.handPokerBg.addChild(movie);*/
                        // StageData.soundObj.soundSinglePlay("tingCard");
                        // StageData.soundObj.soundSinglePlay("dd");
                        this.lsNum ++;    
                        this.showAction();  
                    },this); 
                 }else{
                     egret.Tween.get(this.objList[this.lsNum].obj).wait(100).call(()=>{
                        egret.Tween.removeTweens(this.objList[this.lsNum].obj);
                        this.objList[this.lsNum].obj.showBack(false); 
                        this.lsNum ++;
                        // StageData.soundObj.soundSinglePlay("down");
                        this.showAction();  
                    },this); 
                 }                    
             }else{
                 setTimeout(() => {
                    this.clearLucky()
                 }, 5000)
                 this.dispatchEventWith(this.ON_CLOSE);
             }
    }
}
// 回合结算模块
/*class winningCard extends eui.Component{
    private titleUi:eui.Image;
    private bg:eui.Image;
    private handPokerBg:egret.Sprite;

    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/end/winningCardSkin.exml";
    }
    private onComplete(){
        this.handPokerBg = new egret.Sprite();
        this.handPokerBg.y = 60;
        this.addChild(this.handPokerBg);
    }
    public setContent(msg:any){ 
        let msgList:any = {"bankerIndex":0,"commandCode":20005,"countdownSecond":10,"secure":false,"settlements":[{"actionList":[{"actionCard":{"cardIndex":29,"count":9,"suitType":"T"},"actionCode":2,"actionIndex":2,"actionType":"PENG"},{"actionCard":{"cardIndex":14,"count":4,"suitType":"S"},"actionCode":2,"actionIndex":3,"actionType":"PENG"}],"handList":[{"cardIndex":31,"count":-1,"suitType":"Z"},{"cardIndex":12,"count":2,"suitType":"S"},{"cardIndex":26,"count":6,"suitType":"T"},{"cardIndex":16,"count":6,"suitType":"S"},{"cardIndex":17,"count":7,"suitType":"S"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":25,"count":5,"suitType":"T"},{"cardIndex":12,"count":2,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/JU6qGkMcWsLibvIqeA4Z1X7XhGibVT7zMibibrEeEEv9PkL83puWgKDH4DygPX2q9BQtwoN5TicXkyIGx9qFwEZNPEg/0","nickname":"刘伟","point":6,"presentPoint":6,"seatIndex":0,"suitPatterns":[2],"winCard":{"cardIndex":12,"count":2,"suitType":"S"}},{"actionList":[{"actionCard":{"cardIndex":23,"count":3,"suitType":"T"},"actionCode":2,"actionIndex":1,"actionType":"PENG"}],"handList":[{"cardIndex":2,"count":2,"suitType":"W"},{"cardIndex":12,"count":2,"suitType":"S"},{"cardIndex":3,"count":3,"suitType":"W"},{"cardIndex":14,"count":4,"suitType":"S"},{"cardIndex":15,"count":5,"suitType":"S"},{"cardIndex":16,"count":6,"suitType":"S"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":9,"count":9,"suitType":"W"},{"cardIndex":1,"count":1,"suitType":"W"},{"cardIndex":8,"count":8,"suitType":"W"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/P1gYnyZB9azUrDicY7Iia0DxIm8LEMUNoQ7XAk3N7PjTqAJsCRXRiayVeQkHhMzgamSpmMiaSfTnX53faTSqNSIdCA/0","nickname":"薄荷红茶","point":-2,"presentPoint":-2,"seatIndex":2,"winCard":{"cardIndex":8,"count":8,"suitType":"W"}},{"actionList":[],"handList":[{"cardIndex":31,"count":-1,"suitType":"Z"},{"cardIndex":11,"count":1,"suitType":"S"},{"cardIndex":13,"count":3,"suitType":"S"},{"cardIndex":4,"count":4,"suitType":"W"},{"cardIndex":8,"count":8,"suitType":"W"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":18,"count":8,"suitType":"S"},{"cardIndex":9,"count":9,"suitType":"W"},{"cardIndex":19,"count":9,"suitType":"S"},{"cardIndex":4,"count":4,"suitType":"W"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":18,"count":8,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83epjEPY237UPeHeXoSCG9RxTr1W9Ip1CPzTL3fjyGuvXsosDwppItnSGicfZNJTRujjasolbW0HGaPQ/0","nickname":"し ī п 娜","point":-2,"presentPoint":-2,"seatIndex":1,"winCard":{"cardIndex":18,"count":8,"suitType":"S"}},{"actionList":[],"handList":[{"cardIndex":2,"count":2,"suitType":"W"},{"cardIndex":25,"count":5,"suitType":"T"},{"cardIndex":6,"count":6,"suitType":"W"},{"cardIndex":26,"count":6,"suitType":"T"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":18,"count":8,"suitType":"S"},{"cardIndex":19,"count":9,"suitType":"S"},{"cardIndex":5,"count":5,"suitType":"W"},{"cardIndex":5,"count":5,"suitType":"W"},{"cardIndex":17,"count":7,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/VO9XZrCJy6ZKID2FhEz9MvlPogbibUNCcBg6NY75H3KHVckbf1eHWqCqpcMcJs0f58dlFFgzL85BQ20Ih1gxemA/0","nickname":"A静静","point":-2,"presentPoint":-2,"seatIndex":3,"winCard":{"cardIndex":17,"count":7,"suitType":"S"}}],"step":34,"version":"0.1","zhaMaList":[{"card":{"cardIndex":31,"count":-1,"suitType":"Z"},"win":true},{"card":{"cardIndex":1,"count":1,"suitType":"W"},"win":true},{"card":{"cardIndex":22,"count":2,"suitType":"T"},"win":false},{"card":{"cardIndex":15,"count":5,"suitType":"S"},"win":true},{"card":{"cardIndex":25,"count":5,"suitType":"T"},"win":true},{"card":{"cardIndex":16,"count":6,"suitType":"S"},"win":false},{"card":{"cardIndex":6,"count":6,"suitType":"W"},"win":false},{"card":{"cardIndex":29,"count":9,"suitType":"T"},"win":true}]};
        let bgWidth:number;

        let pokerMc:handPoker;
        for(var i=0;i<msgList.length;i++){
            pokerMc = new handPoker();
            pokerMc.setContent(msgList[i].card.suitType+"_"+msgList[i].card.count+"_png");
            this.handPokerBg.addChild(pokerMc);
            pokerMc.x = pokerMc.width*i;
            if(msgList[i].win){
                pokerMc.y = 0;
            }else{
                pokerMc.y = 10;
            }
            bgWidth = pokerMc.width*i;
        }
        
        if(bgWidth>500){
            this.bg.width = bgWidth+100;
        }else{
            this.bg.width = 550;
        }
        this.handPokerBg.x = (this.bg.width - (pokerMc.width*i))/2;
        this.titleUi.x =  (this.bg.width - this.titleUi.width)/2;
        this.width = this.bg.width;
    }
}*/
/*
回合结束:{"bankerIndex":0,"commandCode":20005,"countdownSecond":10,"secure":false,"settlements":[{"actionList":[{"actionCard":{"cardIndex":29,"count":9,"suitType":"T"},"actionCode":2,"actionIndex":2,"actionType":"PENG"},{"actionCard":{"cardIndex":14,"count":4,"suitType":"S"},"actionCode":2,"actionIndex":3,"actionType":"PENG"}],"handList":[{"cardIndex":31,"count":-1,"suitType":"Z"},{"cardIndex":12,"count":2,"suitType":"S"},{"cardIndex":26,"count":6,"suitType":"T"},{"cardIndex":16,"count":6,"suitType":"S"},{"cardIndex":17,"count":7,"suitType":"S"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":25,"count":5,"suitType":"T"},{"cardIndex":12,"count":2,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/JU6qGkMcWsLibvIqeA4Z1X7XhGibVT7zMibibrEeEEv9PkL83puWgKDH4DygPX2q9BQtwoN5TicXkyIGx9qFwEZNPEg/0","nickname":"刘伟","point":6,"presentPoint":6,"seatIndex":0,"suitPatterns":[2],"winCard":{"cardIndex":12,"count":2,"suitType":"S"}},{"actionList":[{"actionCard":{"cardIndex":23,"count":3,"suitType":"T"},"actionCode":2,"actionIndex":1,"actionType":"PENG"}],"handList":[{"cardIndex":2,"count":2,"suitType":"W"},{"cardIndex":12,"count":2,"suitType":"S"},{"cardIndex":3,"count":3,"suitType":"W"},{"cardIndex":14,"count":4,"suitType":"S"},{"cardIndex":15,"count":5,"suitType":"S"},{"cardIndex":16,"count":6,"suitType":"S"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":9,"count":9,"suitType":"W"},{"cardIndex":1,"count":1,"suitType":"W"},{"cardIndex":8,"count":8,"suitType":"W"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/P1gYnyZB9azUrDicY7Iia0DxIm8LEMUNoQ7XAk3N7PjTqAJsCRXRiayVeQkHhMzgamSpmMiaSfTnX53faTSqNSIdCA/0","nickname":"薄荷红茶","point":-2,"presentPoint":-2,"seatIndex":2,"winCard":{"cardIndex":8,"count":8,"suitType":"W"}},{"actionList":[],"handList":[{"cardIndex":31,"count":-1,"suitType":"Z"},{"cardIndex":11,"count":1,"suitType":"S"},{"cardIndex":13,"count":3,"suitType":"S"},{"cardIndex":4,"count":4,"suitType":"W"},{"cardIndex":8,"count":8,"suitType":"W"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":18,"count":8,"suitType":"S"},{"cardIndex":9,"count":9,"suitType":"W"},{"cardIndex":19,"count":9,"suitType":"S"},{"cardIndex":4,"count":4,"suitType":"W"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":18,"count":8,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83epjEPY237UPeHeXoSCG9RxTr1W9Ip1CPzTL3fjyGuvXsosDwppItnSGicfZNJTRujjasolbW0HGaPQ/0","nickname":"し ī п 娜","point":-2,"presentPoint":-2,"seatIndex":1,"winCard":{"cardIndex":18,"count":8,"suitType":"S"}},{"actionList":[],"handList":[{"cardIndex":2,"count":2,"suitType":"W"},{"cardIndex":25,"count":5,"suitType":"T"},{"cardIndex":6,"count":6,"suitType":"W"},{"cardIndex":26,"count":6,"suitType":"T"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":27,"count":7,"suitType":"T"},{"cardIndex":7,"count":7,"suitType":"W"},{"cardIndex":28,"count":8,"suitType":"T"},{"cardIndex":18,"count":8,"suitType":"S"},{"cardIndex":19,"count":9,"suitType":"S"},{"cardIndex":5,"count":5,"suitType":"W"},{"cardIndex":5,"count":5,"suitType":"W"},{"cardIndex":17,"count":7,"suitType":"S"}],"headUrl":"http://wx.qlogo.cn/mmopen/vi_32/VO9XZrCJy6ZKID2FhEz9MvlPogbibUNCcBg6NY75H3KHVckbf1eHWqCqpcMcJs0f58dlFFgzL85BQ20Ih1gxemA/0","nickname":"A静静","point":-2,"presentPoint":-2,"seatIndex":3,"winCard":{"cardIndex":17,"count":7,"suitType":"S"}}],"step":34,"version":"0.1","zhaMaList":[{"card":{"cardIndex":31,"count":-1,"suitType":"Z"},"win":true},{"card":{"cardIndex":1,"count":1,"suitType":"W"},"win":true},{"card":{"cardIndex":22,"count":2,"suitType":"T"},"win":false},{"card":{"cardIndex":15,"count":5,"suitType":"S"},"win":true},{"card":{"cardIndex":25,"count":5,"suitType":"T"},"win":true},{"card":{"cardIndex":16,"count":6,"suitType":"S"},"win":false},{"card":{"cardIndex":6,"count":6,"suitType":"W"},"win":false},{"card":{"cardIndex":29,"count":9,"suitType":"T"},"win":true}]}*/






